package com.michale.framework.security.context;

import io.swagger.annotations.ApiModelProperty;
import org.springframework.security.core.Authentication;

/**
 * @author SilenceLamb
 * @apiNote 身份验证信息线程
 */
public class AuthenticationContext {
    private static final ThreadLocal<Authentication> context = new ThreadLocal<>();

    @ApiModelProperty("从线程中获取Authentication")
    public static Authentication getAuthentication() {
        return context.get();
    }

    @ApiModelProperty("把Authentication存入线程")
    public static void setAuthentication(Authentication authentication) {
        context.set(authentication);
    }

    @ApiModelProperty("从线程中移除Authentication")
    public static void removeAuthentication() {
        context.remove();
    }
}
